package cn.felord.memberservice.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 全局异常处理.
 * Author: Dax
 * Description:
 * Date: 2018/4/6
 * Time: 19:19
 */

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Map<String, Object> defaultHandler(HttpServletRequest request, Exception e) throws Exception {
        Map<String, Object> result = new HashMap<>();
        result.put("timestamp", System.currentTimeMillis());
        result.put("exception", e.getMessage());
        result.put("url", request.getRequestURI());
        return result;
    }
}
